<template>
    <div>
        <!-- 代售管理 -->
        <div class="all-container">
            <!-- 数据图表栏 -->
            <el-row>
                <el-col :span="24">
                    <avue-crud :data="saleList[0].data" :option="saleList[0].option"  @current-row-change="rowChange" :page="saleList[0].page">
                      <template slot-scope="scope" slot="is_valid">
                        <el-switch
                          v-model="switchList[0]"
                          active-color="#13ce66"
                          inactive-color="#ff4949">
                        </el-switch>
                    </template>
                    </avue-crud>
                </el-col>
            </el-row>
        </div>
    </div>
</template>

<script>
import TableData from "../../components/common/tableData";
export default {
  data: function() {
    return {
      jiGou: "1",
      saleList: [
        {
          page: {
            pageSizes: [10],
            total: 2,
            currentPage: 1,
            pageSize: 10
          },
          data: [],
          option: {
            highlightCurrentRow:true,
            page: false,
            stripe: true,
            menu: false,
            index:true,
            align: "center",
            menuAlign: "center",
            column: []
          }
        }
      ],
      isDeletable: false,
      currentRow:"",
      switchList:[]
    };
  },
  methods: {
    getSaleList() {
      this.postRequest("/sys/org/tree",{
      }).then(data => {
        this.saleList[0].data=data.data;
        this.switchListInit();
        console.log(this.switchList);
        console.log(this.saleList[0].index);
      });
    },
    tableCreate() {
      this.saleList[0].option.column.push(
        {
          label: "机构编号",
          prop: "no"
        },
        {
          label: "简称",
          prop: "name"
        },
        {
          label: "启用代售",
          prop: "is_valid",
          solt:true
        },
      );
    },
    switchListInit(){
      this.switchList=[];
      for(var item of this.saleList[0].data){
        if(item.is_valid==1){
          this.switchList.push(true);
        }else{
          this.switchList.push(false);
        }
      }
    },
    add(){},
    mod(){},
    del(){

    },
    rowChange(val){
      this.currentRow=val
    }
  },
  computed: {},
  components:{TableData},
  watch: {
    switchList(){
      if(this.switchList[0]==true){
        this.getRequest("/distribution/agent/update?distributionOrg.id="+this.currentRow.id+"&distributionOrg.is_enable="+true).then(data=>{
          this.msgShow(data,function(){});
        })
      }else{
        this.getRequest("/distribution/agent/update?distributionOrg.id="+this.currentRow.id+"&distributionOrg.is_enable="+true).then(data=>{
          this.msgShow(data,function(){});
        })
      }
    }
  },
  mounted() {
    console.log("salesManage");
    this.$emit("sendActive", "1-2");
    this.tableCreate();
    this.getSaleList();
  }
};
</script>
<style scoped src="../../assets/css/allManage/salesManage.css">
</style>